//绑定事件
    var addEvent = document.addEventListener ? function(el,type,callback){
        el.addEventListener( type, callback, !1 );
    } : function(el,type,callback){
        el.attachEvent( "on" + type, callback );
    }
//移除事件
    var removeEvent = document.removeEventListener ? function(el,type,callback){
        el.removeEventListener( type, callback );
    } : function(el,type,callback){
        el.detachEvent( "on" + type, callback);
    }
//精确获取样式
    var getStyle = document.defaultView ? function(el,style){
        return document.defaultView.getComputedStyle(el, null).getPropertyValue(style)
    } : function(el,style){
        style = style.replace(/\-(\w)/g, function($, $1){
            return $1.toUpperCase();
        });
        return el.currentStyle[style];
    }
    var dragManager = {
        clientY:0,
        draging:function(e){//mousemove时拖动行
            var dragObj = dragManager.dragObj;
            if(dragObj){
                e = e || event;
                if(window.getSelection){//w3c
                    window.getSelection().removeAllRanges();
                }else  if(document.selection){
                    document.selection.empty();//IE
                }
                var y = e.clientY;
                var down = y > dragManager.clientY;//是否向下移动
                var tr = document.elementFromPoint(e.clientX,e.clientY);
                if(tr && tr.nodeName == "TD"){



                    tr = tr.parentNode
                    dragManager.clientY = y;
                    if( dragObj !== tr){
                        tr.parentNode.insertBefore(dragObj, (down ? tr.nextSibling : tr));
                    }
                };
            }
        },
        dragStart:function(e){
            e = e || event;
            var target = e.target || e.srcElement;
            if(target.nodeName === "TD"){
                target = target.parentNode;
                dragManager.dragObj = target;
                if(!target.getAttribute("data-background")){
                    var background = getStyle(target,"background-color");
                    target.setAttribute("data-background",background)
                }
                if(target.children[4].innerText == '员工号' ||target.children[4].innerText == '员工姓名'
                ||target.children[4].innerText == '身份证号'||target.children[4].innerText == '发放工资日期'){
                    return;
                }
                //显示为可移动的状态
                target.style.boxShadow = "#888 2px 0px 8px";
                target.style.backgroundColor = "#ccc";
                target.style.cursor = "move";
                dragManager.clientY = e.clientY;
                addEvent(document,"mousemove",dragManager.draging);
                addEvent(document,"mouseup",dragManager.dragEnd);
            }
        },
        dragEnd:function(e){
            var dragObj = dragManager.dragObj
            if (dragObj) {
                e = e || event;
                var target = e.target || e.srcElement;
                if(target.nodeName === "TD"){

                    dragObj.style.boxShadow = "";
                    dragObj.style.backgroundColor = dragObj.getAttribute("data-background");
                    dragObj.style.cursor = "default";
                    dragManager.dragObj = null;
                    removeEvent(document,"mousemove",dragManager.draging);
                    removeEvent(document,"mouseup",dragManager.dragEnd);

                    var sequence = [];
                    $('#saltemp-table input[name=inputSalItemOrder]').each(function(){
                        sequence.push(this.value);
                    });
                    var ids = sequence.join(',');
                    $.ajax({ url: basePath+"saltemp/updateSalItemOrder",
                        data: {"ids":ids},
                        type: "POST",
                        success: function(data){
                            if (data.status == 'success') {
                                reLoadPage(rooturl);
                            }else{
                                parent.layer.alert(data.msg);
                            }
                        }
                    })
                }
            }
        },
        main:function(el){
            addEvent(el,"mousedown",dragManager.dragStart);
        }
    }
